"use strict";
var local=false;
var username =local?"root":"AERl8LdKrGP45yNXbqI80OQ7";
var password =local?"":"DsAAf26YxeWo6t95R0EYfo1cbCPRiKxs";
var db_host = local?"127.0.0.1":"sqld.duapp.com";
var db_port = local?3306:4050;
var db_name = local?"test":"QPAOXFRsSsbVJVMhbQON";   //该数据库名为用户在bae平台创建的数据库名称
var mysql      = require('mysql');

var connection = mysql.createConnection({
  host: db_host,
  port: db_port,
  user: username,
  password: password,
  database: db_name
});

exports.sql = function(executesql,params,callback) {
  connection = mysql.createConnection(connection.config);  
	connection.on('error',function(err) {
	  if (err.errno != 'ECONNRESET') {
		throw err;
	  } else {
		//do nothing
	  }
	});
	console.log("是否本地连接:"+local);
	connection.connect();
	connection.query(executesql,params, function(err, rows, fields) {
	  if (err) throw err;
	  callback(rows);

	});
	connection.end();
};
